package chu.dejian.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.sam.widget.badge.BadgeView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import chu.dejian.entity.ContactEntity;
import chu.dejian.entity.MeasureMessageEntity;

/**
 * Created by Administrator on 2016/6/28 0028.
 */
public class AttentionWithBadgeAdapter extends AttentionAdapter {
    private Map<String,List<MeasureMessageEntity>> messageMap;

    public AttentionWithBadgeAdapter(Context context, int layoutResId, List<ContactEntity> contactEntityList, boolean levelEditable) {
        super(context, layoutResId, contactEntityList, levelEditable);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View itemView = super.getView(position, convertView, parent);
        if(messageMap == null) return itemView;
        if(messageMap.get(getItem(position).contactName) != null){
            BadgeView badgeView = new BadgeView(context,itemView);
            badgeView.setText(messageMap.get(getItem(position).contactName).size()+"");
        }
        return itemView;
    }

    public void setAllMessages(List<MeasureMessageEntity> messages){
        if(messages == null || messages.isEmpty()) return;
        messageMap = new HashMap<>();
        for(MeasureMessageEntity messageEntity : messages){
            if(messageMap.get(messageEntity.attendee) == null)
                messageMap.put(messageEntity.attendee,new ArrayList<MeasureMessageEntity>());
            messageMap.get(messageEntity.attendee).add(messageEntity);
        }
    }
}
